<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%-- 
    Document   : header
    Created on : 11 Jan, 2013, 6:47:49 PM
    Author     : s
--%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Companies Management</title>
        <link rel="stylesheet" type="text/css" href="css/theme.css" />
        <link rel="stylesheet" type="text/css" href="css/style.css" />
        <link rel="stylesheet" href="/resources/demos/style.css" />
	<script src="js/jquery-ui-1.8.23.custom/js/jquery-1.7.2.min.js" type="text/javascript"></script>
        
        <link rel="stylesheet" href="js/jquery-ui-1.8.23.custom/development-bundle/themes/base/jquery.ui.all.css">
	<script src="js/jquery-ui-1.8.23.custom/development-bundle/external/jquery.bgiframe-2.1.2.js"></script>
        <script src="js/jquery-ui-1.8.23.custom/development-bundle/ui/jquery.ui.core.js"></script>
	<script src="js/jquery-ui-1.8.23.custom/development-bundle/ui/jquery.ui.widget.js"></script>
	<script src="js/jquery-ui-1.8.23.custom/development-bundle/ui/jquery.ui.mouse.js"></script>
	<script src="js/jquery-ui-1.8.23.custom/development-bundle/ui/jquery.ui.button.js"></script>
	<script src="js/jquery-ui-1.8.23.custom/development-bundle/ui/jquery.ui.draggable.js"></script>
	<script src="js/jquery-ui-1.8.23.custom/development-bundle/ui/jquery.ui.position.js"></script>
	<script src="js/jquery-ui-1.8.23.custom/development-bundle/ui/jquery.ui.resizable.js"></script>
	<script src="js/jquery-ui-1.8.23.custom/development-bundle/ui/jquery.ui.dialog.js"></script>
	<script src="js/jquery-ui-1.8.23.custom/development-bundle/ui/jquery.effects.core.js"></script>
         <script src="js/jquery-ui-1.8.23.custom/development-bundle/ui/jquery.ui.accordion.js"></script>
         <script src="js/jquery-ui-1.8.23.custom/development-bundle/ui/jquery.effects.explode.js"></script>
	<link rel="stylesheet" href="../demos.css">
	<style>
		label, input { display:block; }
		input.text { margin-bottom:12px; width:95%; padding: .4em; }
		fieldset { padding:0; border:0; margin-top:25px; }
		h1 { font-size: 1.2em; margin: .6em 0; }
		div#users-contain { width: 350px; margin: 20px 0; }
		div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
		div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
		.ui-dialog .ui-state-error { padding: .3em; }
		.validateTips { border: 1px solid transparent; padding: 0.3em; }
	</style>
	<script>
	$(function() {
		// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
		
		var com_name = $( "#com_name" ),
			ticker = $( "#ticker" ),
                        com_name1= $("#com_name1"),
                        ticker1 = $ ( "#ticker1" ), 
			allFields = $( [] ).add( com_name ).add( ticker ).add( com_name1 ).add( ticker1 ),
			tips = $( ".validateTips" );

		function updateTips( t ) {
			tips
				.text( t )
				.addClass( "ui-state-highlight" );
			setTimeout(function() {
				tips.removeClass( "ui-state-highlight", 1500 );
			}, 500 );
		}

		function checkLength( o, n, min, max ) {
			if ( o.val().length > max || o.val().length < min ) {
				o.addClass( "ui-state-error" );
				updateTips( "Length of " + n + " must be between " +
					min + " and " + max + "." );
				return false;
			} else {
				return true;
			}
		}

		function checkRegexp( o, regexp, n ) {
			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass( "ui-state-error" );
				updateTips( n );
				return false;
			} else {
				return true;
			}
		}
		
		$( "#dialog-form" ).dialog({
			autoOpen: false,
			height: 300,
			width: 350,
                        show:"explode",
                        hide: "explode",
			modal: true,
			buttons: {
				"Add a Company": function() {
					var bValid = true;
					allFields.removeClass( "ui-state-error" );

					bValid = bValid && checkLength( com_name, "Company Name", 3, 16 );
					bValid = bValid && checkLength( ticker, "Ticker Symbol", 3, 10 );
					

					bValid = bValid && checkRegexp( com_name, /^[a-z]([0-9a-z_])+$/i, "Company Name may consist of a-z, 0-9, underscores, begin with a letter." );
					// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/ticker_address_validation/
										      

					if ( bValid ) {
						$( "#users tbody" ).append( "<tr>" +
                                                    "<td>" + com_name.val() + "</td>" + 
							"<td>" + ticker.val() + "</td>" + 
							"</tr>" ); 
                                            
                                            $("#form1").submit();
						$( this ).dialog( "close" );
                                                
					}
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});

		$("#create")
			.button()
			.click(function() {
				$( "#dialog-form" ).dialog( "open" );
			});
                        
                        
                $("#edit").live('click',function(){
                  
                    var id=$(this).attr("dir").toString();//alert(id);
                    $.getJSON("company_ajax.jsp?id="+id+"",function(data){
                           $("input#com_name1").attr("value",data.name);
                           $("input#ticker1").attr("value",data.ticker);
                           $("input#hid").attr("value",id);
                           $("#com_edit").dialog("open");
                                
                    });
                    
                });
                $( "#com_edit" ).dialog({
			autoOpen: false,
			height: 300,
			width: 350,
                        show:"explode",
                        hide: "explode",
			modal: true,
			buttons: {
				"Edit a Company": function() {
                                    
					var bValid = true;
					allFields.removeClass( "ui-state-error" );
                                        //alert(com_name1.val());
					bValid = bValid && checkLength( com_name1, "Company Name", 3, 16 );
					bValid = bValid && checkLength( ticker1, "Ticker Symbol", 3, 10 );
					

					bValid = bValid && checkRegexp( com_name1, /^[a-z]([0-9a-z_])+$/i, "Company Name may consist of a-z, 0-9, underscores, begin with a letter." );
					// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/ticker_address_validation/
										      

					if ( bValid ) {
						                                  
                                               $("#form2").submit();
						$( this ).dialog( "close" );
                                                
					}
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});

                
                
                 $("#del_com").live('click',function(){
                    var id=$(this).attr("dir").toString();//alert(id);
                    $("input#val").attr("value",id);
                    //alert($("input#val").attr("value"));
                    $( "#del_com_dlg" ).dialog( "open" );
                    
                });
               
				
		
                  
                $( "#del_com_dlg" ).dialog({
			autoOpen: false,
			height: 200,
                        width: 350,
                        show:"explode",
                        hide: "explode",
                        modal:true,
                        buttons: {
				"Delete": function() {
                                    $("#frm").submit();
                                    $(this).dialog("close"); 			
				},
				Cancel: function() {
                                        
					$( this ).dialog( "close" );
				}
			}
		});
	});
	</script>
        <script>
    $(function() {
		$( "#sidebar" ).accordion({
			autoHeight:false,
                        event: "mouseover"
		});
	});
    
</script>
    
        <%@include file="connection.jsp" %>

<!--[if IE]>
<link rel="stylesheet" type="text/css" href="css/ie-sucks.css" />
<![endif]-->
</head>

<body>
	<div id="container">
    	<div id="header">
        	<h2>Stock Market Website</h2>
    <div id="topmenu">
            	<ul>
                    <li><a href="admin_home.jsp">Dashboard</a></li>
                    <li><a href="admin_users.jsp">Users</a></li>
                    <li class="current"><a href="companies.jsp">Companies</a></li>
                    <!--<li><a href="portfolio.jsp">Portfolio</a></li>-->
                 <!--   <li><a href="chatgroup_admin.jsp">Chat Group</a></li>-->
                    <li><a href="experts_admin.jsp">Experts</a></li>
                    <!--                    <li><a href="emails.jsp">Emails</a></li>-->
              </ul>
          </div>
      </div>
<div id="top-panel">
          
          <form action="" name="quoteform" >
              	<input type="text" placeholder="Enter company symbol" name="sym_nm" id="sym_id" />
                <input type="submit" value="Get Stock Value" />
            </form>
          
      </div>        
        <div id="wrapper">
            <div id="content">
                <div id="rightnow">
                    <h3 class="reallynow">
                        <span>Companies</span>
                        <br />
                    </h3>
                   
                    <%
                        st = con.createStatement();
                        rs = st.executeQuery("select * from company");
                     %>
                     
                     <table border='1'>
                         <thead>
                             <tr>
                            <th><center><b>Sr No</b></center></th>
                            <th><center><b>Company Name</b></center></th>
                            <th><center><b>Symbol Ticker </b></center></th>
                            <th><center><b>Operation </b></center></th>
                            </tr>
                    </thead>
                        <%   

                        while(rs.next())
                        {
                            out.print("<tr>");
                                                                           
                            out.print("<td>");
                            out.print(rs.getString(1));
                            out.print("</td>");
                            
                            out.print("<td>");
                            out.print(rs.getString(2));
                            out.print("</td>");
                            
                            out.print("<td>");
                            out.print(rs.getString(3));
                            out.print("</td>");
                            
                            out.print("<td>");
                            out.print("<a href='#' id='edit' dir="+rs.getString(1)+"><img src='img/icons/user_edit.png'></a>");
                            out.print("<a href='#' id='del_com' dir='"+rs.getString(1)+"'><img src='img/icons/user_delete.png'></a>");
                            out.print("</td>");
                            
                        }
                        
                        %>
                     </table>
                    </div>
                        
                     <div id="box">
                         <div class="demo">
                             <div id="del_com_dlg">
                                    <p>Delete this company?</p>
                                </div>
<div id="dialog-form" title="Add a Company">
	<p class="validateTips">All form fields are required.</p>

        <form action="company_back.jsp?op=add" id="form1" method="POST">
	<fieldset>
		<label for="com_name">Company Name</label>
		<input type="text" name="com_name" id="com_name" class="text ui-widget-content ui-corner-all" />
		<label for="ticker">Ticker Symbol</label>
		<input type="text" name="ticker" id="ticker" value="" class="text ui-widget-content ui-corner-all" />
		</fieldset>
	</form>
</div>
                            
<button id="create">Add a Company</button>

<div id="com_edit" title="Edit a Company">
	<p class="validateTips">All form fields are required.</p>

        <form action="company_back.jsp?op=edit" id="form2" method="POST">
	<fieldset>
		<label for="com_name">Company Name</label>
		<input type="text" name="com_name" id="com_name1" class="text ui-widget-content ui-corner-all" />
		<label for="ticker">Ticker Symbol</label>
		<input type="text" name="ticker" id="ticker1" class="text ui-widget-content ui-corner-all" />
                <input type="hidden" name="hid" id="hid"/>
		</fieldset>
	</form>
</div>
</div><!-- End demo -->
        <form action='company_back.jsp' id='frm'>
            <input type='hidden' name='val' id="val"/>
            <input type='hidden' name='op' value='delete'/>
        </form>
                     </div>
            </div>
   <div id="sidebar">
  	
                	<li><h3><a href="#" class="house">Dashboard</a></h3>
                        <ul>
                        	<li><a href="logout.jsp" class="report">Logout</a></li>
                        </ul>
                    </li>
                    
				       
          </div>
      </div>
        <div id="footer">
        <div id="styleswitcher">
            <ul>
                <li><a href="javascript: document.cookie='theme='; window.location.reload();" title="Default" id="defswitch">d</a></li>
                <li><a href="javascript: document.cookie='theme=1'; window.location.reload();" title="Blue" id="blueswitch">b</a></li>
                <li><a href="javascript: document.cookie='theme=2'; window.location.reload();" title="Green" id="greenswitch">g</a></li>
                <li><a href="javascript: document.cookie='theme=3'; window.location.reload();" title="Brown" id="brownswitch">b</a></li>
                <li><a href="javascript: document.cookie='theme=4'; window.location.reload();" title="Mix" id="mixswitch">m</a></li>
                <li><a href="javascript: document.cookie='theme=5'; window.location.reload();" title="Mix" id="defswitch">m</a></li>
            </ul>
        </div><br />

        </div>
</div>
</body>
</html>

